package com.ruoyi.cencat.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cencat.domain.CencatGoods;
import com.ruoyi.cencat.service.ICencatGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货物信息Controller
 * 
 * @author cencat
 * @date 2024-05-21
 */
@RestController
@RequestMapping("/cencat/goods")
public class CencatGoodsController extends BaseController
{
    @Autowired
    private ICencatGoodsService cencatGoodsService;

    /**
     * 查询货物信息列表
     */
    @PreAuthorize("@ss.hasPermi('cencat:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(CencatGoods cencatGoods)
    {
        startPage();
        List<CencatGoods> list = cencatGoodsService.selectCencatGoodsList(cencatGoods);
        return getDataTable(list);
    }

    /**
     * 导出货物信息列表
     */
    @PreAuthorize("@ss.hasPermi('cencat:goods:export')")
    @Log(title = "货物信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CencatGoods cencatGoods)
    {
        List<CencatGoods> list = cencatGoodsService.selectCencatGoodsList(cencatGoods);
        ExcelUtil<CencatGoods> util = new ExcelUtil<CencatGoods>(CencatGoods.class);
        util.exportExcel(response, list, "货物信息数据");
    }

    /**
     * 获取货物信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('cencat:goods:query')")
    @GetMapping(value = "/{goodId}")
    public AjaxResult getInfo(@PathVariable("goodId") Long goodId)
    {
        return success(cencatGoodsService.selectCencatGoodsByGoodId(goodId));
    }

    /**
     * 新增货物信息
     */
    @PreAuthorize("@ss.hasPermi('cencat:goods:add')")
    @Log(title = "货物信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CencatGoods cencatGoods)
    {
        return toAjax(cencatGoodsService.insertCencatGoods(cencatGoods));
    }

    /**
     * 修改货物信息
     */
    @PreAuthorize("@ss.hasPermi('cencat:goods:edit')")
    @Log(title = "货物信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CencatGoods cencatGoods)
    {
        return toAjax(cencatGoodsService.updateCencatGoods(cencatGoods));
    }

    /**
     * 删除货物信息
     */
    @PreAuthorize("@ss.hasPermi('cencat:goods:remove')")
    @Log(title = "货物信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodIds}")
    public AjaxResult remove(@PathVariable Long[] goodIds)
    {
        return toAjax(cencatGoodsService.deleteCencatGoodsByGoodIds(goodIds));
    }
}
